package com.pig.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pig.pojo.cart.Cart;
import com.pig.pojo.order.OrderItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CartMapper extends BaseMapper<Cart> {

    @Select("SELECT  cartId,itemId,itemTitle,createdTime,num,itemPrice,userId,modifiedTime,itemImage  FROM  p_cart  WHERE userId = #{userId}")
    List<Cart> selectItemsByUserId(Integer userId);

    @Update("UPDATE p_cart  SET  num=#{num}  WHERE cartId = #{cartId} ")
    void updateNum(Integer cartId, Integer num);

    /*@Delete("DELETE FROM p_cart WHERE cartId=#{cartId}")
    void delItemCartById(Integer cartId);*/

    @Select("SELECT  cartId,itemId,itemTitle,createdTime,num,itemPrice,userId,modifiedTime,itemImage  FROM  p_cart  WHERE userId =#{userId}")
    List<OrderItem> selectOrderItemsByUserId(Integer userId);

    @Delete("DELETE FROM p_cart WHERE userId=#{userId}")
    void deleteCartByUserId(Integer userId);
}
